package com.dream.tihai.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dream.tihai.entity.AskEntity;
import com.dream.tihai.mapper.AskMapper;
import com.dream.tihai.service.IAskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * @author Valley
 * Created by Valley on 2022/9/5
 */
@Service
public class AskServiceImpl implements IAskService {

    @Autowired
    AskMapper askMapper;

    @Override
    public List<AskEntity> selectAll(Integer typeId) {
        LambdaQueryWrapper<AskEntity> wrapper = new LambdaQueryWrapper<AskEntity>()
                .eq(AskEntity::getTypeId, typeId);
        List<AskEntity> askList = askMapper.selectList(wrapper);
        Collections.reverse(askList);
        return askList;
    }

    @Override
    public void add(String title, String answer, Integer typeId) {
        AskEntity ask = new AskEntity(null, title, answer, typeId);
        int insert = askMapper.insert(ask);
    }
}
